<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript">
    $(function () {
        $('.land-table').dataTable({
            "sPaginationType": "full_numbers",
            "bDestroy": true,
            "oLanguage": {
                "sZeroRecords": $('#no-record').val(),
                "sLengthMenu": $('#display').val() + " _MENU_ " + $('#records').val(),
                "sSearch": $('#search').val(),
                "sInfo": $('#showing').val() + " _START_ " + $('#to').val() + " _END_ " + $('#of').val() + " _TOTAL_ " + $('#entries').val(),
                "sInfoEmpty": $('#no-record').val(),
                "oPaginate": {
                    "sFirst": $('#first').val(),
                    "sLast": $('#last').val(),
                    "sNext": $('#next').val(),
                    "sPrevious": $('#previous').val()
                }
            },
            "fnDrawCallback": function () {
                if ($('.dataTables_paginate span span.paginate_button').size()) {
                    $('.dataTables_paginate')[0].style.display = "block";
                } else {
                    $('.dataTables_paginate')[0].style.display = "none";
                }
            }
        });
    });

    $(function () {


        $('select#district').bind('change', function (evt1) {
            var id = $("select#district").attr("value");
            $.getJSON('${pageContext.request.contextPath}/common/DivisionLookupService', {id: id, mode: 2},
                    function (data) {
                        var options1 = '<option value="0"> - Select  - </option> ';
                        var ds = data.dsDivisionList;
                        for (var i = 0; i < ds.length; i++) {
                            options1 += '<option value="' + ds[i].optionValue + '">' + ds[i].optionDisplay + '</option>'

                        }
                        $("select#dsDivision").html(options1);
                    });

        });
    });

</script>
<div id="land-registration-module-home-title" class="module-home-title">
    <s:a href="searchModule.do"><img src="${pageContext.request.contextPath}/images/search.png"
                                     alt="Land Alienation"><span><s:label
            value="%{getText('search.label')}"/></span></s:a>
    <span class="module-title-breaker"> > </span>
    <s:a href="loadApplicationSearchPage.do"><img
            src="${pageContext.request.contextPath}/images/search_by_reference.png"><span><s:label
            value="%{getText('search_application.label')}"/></span></s:a>
    <div id="back-button" align="right">
                <s:form><s:submit value="%{getText('back_btn.label')}" action="searchModule"/></s:form>
    </div>
</div>
<%--<s:include value="../notifications.jsp"/>--%>

<h2><s:label value="%{getText('search_application.label')}"/></h2>

<div id="search-lands-form-outer">
    <table>
        <tr>
            <s:form name="searchApplicationList" id="searchApplicationList" method="POST">
                <s:if test="#session.userGroup=='orlm' || #session.userGroup=='ords' || #session.userGroup=='lo'">
                    <td class="left-align"><s:label value="%{getText('ds_division.label')}"/></td>
                    <td><s:textfield value="%{user.getDsDivisions().iterator().next().getEnDivisionName()}"
                                     cssClass="width-220-px"
                                     disabled="true"/></td>
                    <s:hidden name="dsDivisionId" value="%{user.getDsDivisions().iterator().next().getId()}"/>

                </s:if>
                <s:else>
                    <td class="left-align"><s:label value="%{getText('district.label')}"/></td>
                    <td><s:select list="districtList" name="districtId" headerKey="0" headerValue="-- Select --"
                                  id="district"/></td>
                    <td class="left-align"><s:label value="%{getText('ds_division.label')}"/></td>
                    <td><s:select name="dsDivisionId" id="dsDivision" headerKey="0" headerValue="-- Select --"
                                  list="dsDivisionList" cssClass="width-180-px"/>
                    </td>
                </s:else>
                <td><s:submit action="searchApplicationList" value="%{getText('search.label')}"/></td>
            </s:form>
        </tr>
        <tr>
            <s:form name="searchApplicationByPersonName" id="searchApplicationByPersonName" method="POST">
                <td><s:label value="%{getText('name.label')}"/></td>
                <td><s:textfield name="searchText" id="searchTextPersonName"/></td>
                <td><s:submit action="searchApplicationByPersonName" value="%{getText('search.label')}"/></td>
            </s:form>

        </tr>
        <tr>
            <s:form name="searchApplicationByNIC" id="searchApplicationByNIC" method="POST">
                <td><s:label value="%{getText('NIC_number.label')}"/></td>
                <td><s:textfield name="searchText" id="searchTextNIC"/></td>
                <td><s:submit action="searchApplicationByNIC" value="%{getText('search.label')}"/></td>
            </s:form>
        </tr>
    </table>
</div>
<table class="width-100 margin-10-auto table land-table">
    <thead>
    <tr class="center-align table-header">
        <%-- <th><s:label value="%{getText('refNo.label')}"/></th>  --%>
        <th><s:label value="%{getText('applied_date.label')}"/></th>
        <th><s:label value="%{getText('applicant_name.label')}"/></th>
        <th><s:label value="%{getText('state.label')}"/></th>
        <th><s:label value="%{getText('action.label')}"/></th>
    </tr>
    </thead>
    <tbody>
    <s:iterator status="status" value="landApplicationList">
        <tr class="<s:if test="#status.odd == true">table-row-odd</s:if><s:else>table-row-even</s:else>">
                <%-- <td class="center-align"><s:property value="refNumber"/></td> --%>
            <td class="center-align"><s:property value="submitDate"/></td>
            <td class="center-align"><s:property value="holder.name"/></td>
            <s:if test="workflowItem != null">
                <td class="center-align"><s:label name="workflowItem.workflowTask.action"/></td>
            </s:if>
            <s:else>
                <td class="center-align"><s:property value="initialStatus"/></td>
            </s:else>
            <td class="center-align">
                <s:url id="initDetailApplication" action="initDetailApplication">
                    <s:param name="applicationId" value="id"/>
                    <%-- TODO: set edit mode to 3 in detail page. set edit mode to 4 if approve only button should appear --%>
                    <s:param name="editMode" value="editMode"/>
                    <s:param name="searchValue" value="1"/>
                </s:url>

                <s:a href="%{initDetailApplication}" title="%{getText('view_tooltip.label')}">
                    <img src="<s:url value='/images/detailed-form.png'/>" border="none" width="25"
                         height="25"/>
                </s:a>

                <s:if test="workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@CONDITION_SATISFIED">
                    <s:url id="getAgreementType" action="getAgreementType">
                        <s:param name="applicationId" value="id"/>

                    </s:url>
                    <s:a href="%{getAgreementType}" title="%{getText('view_agreement_tooltip')}">
                        <img src="<s:url value='/images/agreement.png'/>" border="none" width="25"
                             height="25"/>
                    </s:a>
                </s:if>

            </td>

                <%--<td class="center-align">

                    <s:if test="status.ordinal() == 0 || status.ordinal() == 1 || status.ordinal() == 3">
                        <s:url id="editInitApplication" action="editInitApplication">
                            <s:param name="applicationId" value="id"/>
                            <s:param name="editMode" value="editMode"/>
                        </s:url>
                        <s:a href="%{editInitApplication}" title="%{getText('view_tooltip.label')}">
                            <img src="<s:url value='/images/init-form.png'/>" border="none" width="25"
                                 height="25"/>
                        </s:a>

                    </s:if>
                    <s:else>
                        <s:url id="initDetailApplication" action="initDetailApplication">
                            <s:param name="applicationId" value="id"/>
                            <s:param name="editMode" value="editMode"/>
                        </s:url>
                        <s:a href="%{initDetailApplication}" title="%{getText('view_tooltip.label')}">
                            <img src="<s:url value='/images/detailed-form.png'/>" border="none" width="25"
                                 height="25"/>
                        </s:a>

                    </s:else>


                </td>--%>
        </tr>
    </s:iterator>
    </tbody>
</table>

<s:hidden id="appliedDate" value="%{getText('applied_date.label')}"/>
<s:hidden id="applicantName" value="%{getText('applicant_name.label')}"/>

<%-- Localization text for data tables --%>
<s:hidden id="display" value="%{getText('display.label')}"/>
<s:hidden id="records" value="%{getText('records.label')}"/>
<s:hidden id="search" value="%{getText('search.label')}"/>
<s:hidden id="no-record" value="%{getText('no_record.label')}"/>
<s:hidden id="showing" value="%{getText('showing.label')}"/>
<s:hidden id="to" value="%{getText('to.label')}"/>
<s:hidden id="of" value="%{getText('of.label')}"/>
<s:hidden id="entries" value="%{getText('entries.label')}"/>
<s:hidden id="first" value="%{getText('first.label')}"/>
<s:hidden id="last" value="%{getText('last.label')}"/>
<s:hidden id="next" value="%{getText('next.label')}"/>
<s:hidden id="previous" value="%{getText('previous.label')}"/>